package com.ktwlsoft.archivemanage.domain.business.repositoryService.businessInspect;

import java.time.Year;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.ktwlsoft.archivemanage.domain.dao.entity.businessInspect.BusinessInspect;
import com.ktwlsoft.archivemanage.domain.dao.repository.businessInspect.IBusinessInspectMapper;
import com.ktwlsoft.archivemanage.payload.businessInspect.EfficiencyOfGuidanceAndMendOfPoint;
import com.ktwlsoft.archivemanage.payload.businessInspect.InspectEfficiencyPoint;
import com.ktwlsoft.archivemanage.payload.recycle.DeleteRequest;
import com.ktwlsoft.archivemanage.payload.recycle.QueryRecycleRequest;
import com.ktwlsoft.archivemanage.payload.view.GuidanceVariation;
import com.ktwlsoft.archivemanage.payload.view.MarkLostResponse;
import com.ktwlsoft.archivemanage.payload.view.UnitMarkResponse;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * business_inspect--业务检查业务层接口实现类
 *
 * @author zhuhe on 2019-11-12 15:00:45
 * @version 1.0
 */
@Service
public class BusinessInspectRepositoryService {

    private final IBusinessInspectMapper businessInspectMapper;

    public BusinessInspectRepositoryService(IBusinessInspectMapper businessInspectMapper) {
        this.businessInspectMapper = businessInspectMapper;
    }

    /**
     * 查询分页 on 2019-11-12 15:00:45
     *
     * @param pn               第几页
     * @param pageSize         每页多少条
     * @param businessInspect businessInspect
     * @return PageInfo<BusinessInspect>
     */
    public PageInfo<BusinessInspect> findPage(int pn, int pageSize, BusinessInspect businessInspect) {
        PageHelper.startPage(pn, pageSize);
        PageInfo<BusinessInspect> pageInfo = new PageInfo<BusinessInspect>(businessInspectMapper.findList(businessInspect));
        return pageInfo;
    }

    /**
     * 查询分页 on 2019-11-12 15:00:45
     *
     * @param pn         第几页
     * @param pageSize   每页多少条
     * @param jsonObject jsonObject
     * @return PageInfo<BusinessInspect>
     */
    public PageInfo<BusinessInspect> findPage(int pn, int pageSize, JSONObject jsonObject) {
        PageHelper.startPage(pn, pageSize);
        PageInfo<BusinessInspect> pageInfo = new PageInfo<BusinessInspect>(businessInspectMapper.findListJson(jsonObject));
        return pageInfo;
    }

    /**
     * 查询分页 on 2019-11-12 15:00:45
     *
     * @param pn         第几页
     * @param pageSize   每页多少条
     * @param jsonObject jsonObject
     * @return PageInfo<BusinessInspect>
     */
    public PageInfo<JSONObject> selfOrRepeatFindListJson(int pn, int pageSize, JSONObject jsonObject) {
        PageHelper.startPage(pn, pageSize);
        PageInfo<JSONObject> pageInfo = new PageInfo<JSONObject>(businessInspectMapper.selfOrRepeatFindListJson(jsonObject));
        return pageInfo;
    }

    /**
     * 查询集合 on 2019-11-12 15:00:45
     *
     * @param businessInspect businessInspect
     * @return List<BusinessInspect>
     */
    public List<BusinessInspect> findList(BusinessInspect businessInspect) {
        return businessInspectMapper.findList(businessInspect);
    }

    /*查询指导人*/
    public List findInstructors() {
        return businessInspectMapper.findInstructors();
    }

    /**
     * 根据ID查询信息 on 2019-11-12 15:00:45
     *
     * @param id 主键
     * @return BusinessInspect
     */
    public BusinessInspect getById(Long id) {
        return businessInspectMapper.getById(id);
    }

    /**
     * 根据指导单号查询数据 on 2019/11/21 14:43
     *
     * @param guidanceNum guidanceNum
     * @return BusinessInspect
     */
    public List<BusinessInspect> getByGuidanceNum(String guidanceNum) {
        return businessInspectMapper.getByGuidanceNum(guidanceNum);
    }

    /**
     * 新增 on 2019-11-12 15:00:45
     *
     * @param businessInspect businessInspect
     * @return int
     */
    public int insert(BusinessInspect businessInspect) {
        return businessInspectMapper.insert(businessInspect);
    }

    /**
     * 修改 on 2019-11-12 15:00:45
     *
     * @param businessInspect businessInspect
     * @return int
     */
    public int update(BusinessInspect businessInspect) {
        return businessInspectMapper.update(businessInspect);
    }

    /**
     * 根据id集合批量删除信息 on 2019-11-12 15:00:45
     *
     * @param businessGuidanceArr 主键编号集合
     * @return int
     */
    public int deleteByIds(List<Long> businessGuidanceArr) {
        return businessInspectMapper.deleteByIds(businessGuidanceArr);
    }

    /**
     * 根据id删除信息 on 2019-11-12 15:00:45
     *
     * @param id id
     * @return int
     */
    public int deleteById(Long id) {
        return businessInspectMapper.deleteById(id);
    }

    public List<JSONObject> findRecycle(QueryRecycleRequest request) {
        return businessInspectMapper.findRecycle(request);
    }

    public int restore(List<Long> ids) {
        return businessInspectMapper.restore(ids);
    }

    public List<InspectEfficiencyPoint> getAvgMarkOfYearsOfInstructor(Long archivistId, Year year) {
        return businessInspectMapper.getAvgMarkOfYearsOfInstructor(archivistId, year);
    }

    public List<InspectEfficiencyPoint> getSelfOrRepeatAvgMarkOfYearsOfInstructor(Long archivistId, Year year) {
        return businessInspectMapper.getSelfOrRepeatAvgMarkOfYearsOfInstructor(archivistId, year);
    }

    public List<EfficiencyOfGuidanceAndMendOfPoint> getEfficiencyOfGuianceAndMend(Year year) {
        return businessInspectMapper.getEfficiencyOfGuianceAndMend(year);
    }

    public List<EfficiencyOfGuidanceAndMendOfPoint> getSelfOrRepeatEfficiencyOfGuianceAndMend(Year year) {
        return businessInspectMapper.getSelfOrRepeatEfficiencyOfGuianceAndMend(year);
    }

    public List<MarkLostResponse> getMarkLostRanking(Year year, String guidNum) {
        return businessInspectMapper.getMarkLostRanking(year, guidNum);
    }

    public List<UnitMarkResponse> getUnitMarkReanking(Year year) {
        return businessInspectMapper.getUnitMarkReanking(year);
    }

    public List<GuidanceVariation> getGuidanceVariationOfYear() {
        return businessInspectMapper.getGuidanceVariationOfYear();
    }

    public List getGuidNumsByYear(String createdAtFrom, String createdAtTo) {
        return businessInspectMapper.getGuidNumsByYear(createdAtFrom, createdAtTo);
    }

    /**
     * 获取当前指导人已上报条数
     *
     * @param userId userId
     * @return String
     */
    public String getRecorderMount(Long userId) {
        return businessInspectMapper.getRecorderMount(userId);
    }
}
